<?php
require_once('Xml/Info/Provider.php');

class Xml_Factory {
    const OUTPUT_TYPE_TEXT = 'xml';
    const OUTPUT_TYPE_FILE = 'file';

    const TYPE_RSS = 'rss';
    const TYPE_SITEMAP = 'sitemap';

    public static function factory($_type = false, $_output = false) {
        if ($_type == false) 
            $_type = self::TYPE_RSS;
        if ($_output == false) 
            $_output = self::OUTPUT_TYPE_TEXT;

        $instance = null;
        if (!in_array($_output, array(self::OUTPUT_TYPE_TEXT, self::OUTPUT_TYPE_FILE))) {
            throw new Xml_Exception("Un-recognise output '$_output' in Xml_Factory");
        }
        $_strategy = null;
        if ($_output == self::OUTPUT_TYPE_TEXT) {
            require_once('Xml/Strategy/Text.php');
            $_strategy = new Xml_Strategy_Text();
        }else{
            require_once('Xml/Strategy/File.php');
            $_strategy = new Xml_Strategy_File();
        }
        switch(strtolower($_type)) {
           case self::TYPE_RSS:
                require_once('Xml/Rss.php');
                $instance = new Xml_Rss(new Xml_Info_Provider(), $_strategy);
                break;
           case self::TYPE_SITEMAP:
                require_once('Xml/Sitemap.php');
                $instance = new Xml_Sitemap(new Xml_Info_Provider(), $_strategy);
                break;
            default:
                throw new Xml_Exception("Un-recognise type '$_type' in Xml_Factory");
        }
        return $instance;
    }
}
